package com.example.service.impl;

import com.example.mapper.macTestConMapp;
import com.example.pojo.macTestConPojo;
import com.example.pojo.macTestConValPojo;
import com.example.service.macTestConService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:macTestConImpl
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/12/30 15:32
 * @Version 1.0
 */
@Service
public class macTestConImpl implements macTestConService {
    //注入Mapper层
    @Autowired
    private macTestConMapp macTestconMapp;
//    插入一行
    public void insertOne(macTestConPojo macTestConPojo){
        //时间赋值
        macTestConPojo.setEstablishTime(LocalDateTime.now());
        macTestConPojo.setUpdateTime(LocalDateTime.now());
        macTestconMapp.insertOne(macTestConPojo);
    }
    //输入三个字段，进行查询,适用查询的是三个字符串格式的数据
    public List<macTestConPojo> inquiryThreeField(Map<String, Object> map){
        String firstFieldName=(String) map.get("firstFieldName");
        String firstFieldVal=(String) map.get("firstFieldVal");
        String secondFieldName=(String) map.get("secondFieldName");
        String secondFieldVal=(String) map.get("secondFieldVal");
        String thirdName=(String) map.get("thirdName");
        String thirdVal=(String) map.get("thirdVal");
        List<macTestConPojo> macTestConPojoList=macTestconMapp.inquiryThreeField(firstFieldName,firstFieldVal,secondFieldName,secondFieldVal,thirdName,thirdVal);
        return macTestConPojoList;
    }
    //输入四个字段，进行查询
    public List<macTestConPojo> inquiryFourthField(Map<String, Object> map){
        String firstFieldName=(String) map.get("firstFieldName");
        String firstFieldVal=(String) map.get("firstFieldVal");
        String secondFieldName=(String) map.get("secondFieldName");
        String secondFieldVal=(String) map.get("secondFieldVal");
        String thirdName=(String) map.get("thirdName");
        String thirdVal=(String) map.get("thirdVal");
        String fourthFieldName=(String) map.get("fourthFieldName");
        String fourthFiledVal=(String) map.get("fourthFiledVal");
        List<macTestConPojo> macTestConPojoList=macTestconMapp.inquiryFourthField(firstFieldName,firstFieldVal,secondFieldName,secondFieldVal,thirdName,thirdVal,fourthFieldName,fourthFiledVal);
        return macTestConPojoList;
    }
    //一次插入多行数据
    public void testValMacTestCon(List<macTestConValPojo> macTestConValPojos){
        for (int i = 0; i < macTestConValPojos.size(); i++) {
            //设置创立时间
            macTestConValPojos.get(i).setUpdateTime(LocalDateTime.now());
            macTestConValPojos.get(i).setEstablishTime(LocalDateTime.now());
        }
        macTestconMapp.testValMacTestCon(macTestConValPojos);
    }
    //根据id，修改一整行。
    public void macTestConEditOne(macTestConPojo macTestConPojo){
        //组合修改时间
        macTestConPojo.setUpdateTime(LocalDateTime.now());
        System.out.println(macTestConPojo.getUpdateTime());
        //向修改数据
        Integer id = macTestConPojo.getId();
        macTestconMapp.editOne(id,macTestConPojo);
    }
    //修改一个字段.依据id
    public void macTestConEditOneField(Map<String, Object> map){
        Integer id = (Integer) map.get("id");
        String firstFieldName = (String) map.get("firstFieldName");
        Integer firstFieldVal = (Integer) map.get("firstFieldVal");
        LocalDateTime updateTime=LocalDateTime.now();
        System.out.println(firstFieldVal);
        macTestconMapp.oneField(id,firstFieldName,firstFieldVal,updateTime);
    }
    //接收5个参数，查询出检测结果。
    public List<macTestConValPojo> macTestConValInquiryFiveField(Map<String, Object> map){
        String firstFieldName=(String) map.get("firstFieldName");
        String firstFieldVal=(String) map.get("firstFieldVal");
        String secondFieldName=(String) map.get("secondFieldName");
        String secondFieldVal=(String) map.get("secondFieldVal");
        String thirdName=(String) map.get("thirdName");
        String thirdVal=(String) map.get("thirdVal");
        String fourthName=(String) map.get("fourthName");
        String fourthVal=(String) map.get("fourthVal");
        String fifthName=(String) map.get("fifthName");
        int fifthVal=(Integer) map.get("fifthVal");

        if (fourthName.equals("nothing")){
            //没有特性值，按照三个特性和一个最近数量筛选
            List<macTestConValPojo> macTestConValPojos=macTestconMapp.macTestConValInquiryFourField(firstFieldName,firstFieldVal,secondFieldName,secondFieldVal,thirdName,thirdVal,fifthVal);
            return macTestConValPojos;
        }
        else {
            List<macTestConValPojo> macTestConValPojos=macTestconMapp.macTestConValInquiryFiveField(firstFieldName,firstFieldVal,secondFieldName,secondFieldVal,thirdName,thirdVal,fourthName,fourthVal, fifthVal);
            return macTestConValPojos;
        }
    }
}
